package com.wyd.jwpkglxt_ssm.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object token = session.getAttribute("token");
        if(Objects.isNull(token)){
            response.sendRedirect(request.getContextPath()+"/index/login");
            System.out.println("我被拦截器拦截了");
            return false;
        }
        System.out.println("我通过了拦截器");
        return true;
    }
}
